// pages/demand/offer-success.js
const app = getApp()
Page({

    data: {
        more: false
    },

    onLoad: function(options) {
        this.setData(options)
        this.loadData()
    },
    /**
     * offerInfo.status 1待中标  2 已中标 3 已撤销
     */
    loadData() {
        wx.showLoading({
            title: '加载中...',
        })
        Promise.all([
            app.http.post('rest/ticket/queryById.do', {
                data: this.data.id
            }),
            app.http.post('rest/quote/queryById.do', {
                data: this.data.cid
            })
        ]).then(res => {
            this.setData(Object.assign({
                offerInfo: res[1].obj,
            }, res[0].obj))
            wx.hideLoading()
        })
    },
    more() {
        this.setData({
            more: !this.data.more
        })
    },
    //撤销报价
    revoke() {
        wx.showModal({
            title: '温馨提示',
            content: '您确定要撤销报价吗',
            confirmColor: '#4DB4FF',
            success: res => {
                if (res.confirm) {
                    wx.showLoading({
                        title: '请稍等',
                    })
                    app.http.post('rest/quote/revoke.do', {
                        data: this.data.cid
                    }).then(res => {
                        wx.hideLoading()
                        wx.showToast({
                            title: '撤销报价成功',
                        })
                        this.loadData()
                    })
                }
            }
        })
    },
    returnOfferList() {
        if (app.getPrevPage() && app.getPrevPage().route == 'pages/agency/demand/demand-detail') {
            wx.navigateBack({
				delta:2
			})
            return
        }
        wx.redirectTo({
            url: '/pages/agency/demand/demand-list',
        })
    },
	// onUnload() {
	// 	if (app.getPrevPage().route = 'pages/agency/demand/demand-detail') {
	// 		wx.redirectTo({
	// 			url: '/pages/agency/personal/agency-list',
	// 		})
	// 	}
	// }
})